import { ajax } from '../libs/ajax.js';

let txt_title = document.getElementById('txt_title');
let txt_source = document.getElementById('txt_source');
let txt_info = document.getElementById('txt_info');
let btnOk = document.getElementById('btnOk');
let btnback = document.getElementById('btnback');

btnOk.addEventListener('click', () => {
  let bbd = {
    title: txt_title.value,
    username: txt_source.value,
    content: txt_info.value,
  };

  ajax.post('/crud/billboard', bbd, (data) => {
    alert(data.message);
    if (data.success) {
      txt_title.value = '';
      txt_source.value = '';
      txt_info.value = '';
    }
  });
});

btnback.addEventListener('click', () => {
  location.href = 'bbd.html';
});
